
static char RCSId[]="$Id: Pane.m,v 1.1.1.1 1993/03/18 03:34:50 davis Exp $";


#import <appkit/Application.h>
#import <appkit/Matrix.h>
#import <appkit/Text.h>			/* Pane's can be text delegates */
#import <appkit/TextFieldCell.h>
#import "Pane.h"


@implementation Pane


- init
{
    [super init];

    title = NULL;
    icon = NULL;
    view = nil;
    status = nil;
    doc = nil;

    isCurrentPane = NO;

    _textCellChanged = NO;

    return self;
}


- view
{
    return view;
}



- (const char *) icon
{
    return icon;
}


- setTitle: (const char *) aString
{
    NXZone *zone;

    NXZoneFree (zone = [self zone], title);

    if (aString)
	title = NXCopyStringBufferFromZone (aString, zone);
    else
	title = NULL;

    return self;
}

	
- (const char *) title
{
    return title;
}


- selectControl:sender
{
    return nil;
}


/*  
 *  Returns YES if the pane has changed and the view needs to be 
 *  redisplayed.
 */
- (BOOL)updateStatus:aStatus doc:aDoc
{
    if (aStatus && aDoc) {
	status = aStatus;
	doc = aDoc;
	return YES;
    } else
	return NO;
}


/*  
 *  Returns YES if the pane has changed and the view needs to be 
 *  redisplayed.
 */
- (BOOL)forceUpdateStatus:aStatus doc:aDoc
{
    status = nil;
    doc = nil;
    return [self updateStatus:aStatus doc:aDoc];
}



- didSwapIn:sender
{
    isCurrentPane = YES;
    return self;
}


- didSwapOut:sender
{
    isCurrentPane = NO;
    return self;
}


- textDidEnd:textObject endChar:(unsigned short)whyEnd
{
    /*  
     *  Under most circumstances, the superview of the textObject is 
     *  the Cell that was being edited.  All of the TextFieldCells in 
     *  the Panes, however, are assumed to be scrollable (so the user 
     *  can enter numbers larger than the space that I've allowed), so 
     *  the superview of the textObject is a ClipView.  The Cell we 
     *  want is the super view of the ClipView.
     */
    id matrix = [[textObject superview] superview];
    id editCell = [matrix selectedCell];

    if (_textCellChanged && ((whyEnd == NX_TAB) || (whyEnd == NX_BACKTAB)))  {

	if ([editCell action])	/* If cell has its own action, do it	*/
	    [[editCell controlView]
		sendAction:[editCell action] to:[editCell target]];

	else			/* Otherwise, do the matrix's action	*/
	    [matrix sendAction:[matrix action] to:[matrix target]];

	_textCellChanged = NO;

    }

    return self;
}



- (BOOL) textWillChange:textObject
{
    _textCellChanged = YES;
    return NO;		/* NO means it's okay for the text to change	*/
}


// Shuts up the compiler about unused RCSId
- (const char *) rcsid
{
    return RCSId;
}


@end
